//
//  HomeViewController.m
//  MobileOffice
//
//  Created by Appel on 16/10/11.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "HomeViewController.h"
#import "ApplicationListViewController.h"
#import "PersonCenterViewController.h"
#import "SZCalendarPicker.h"
#import "Home1TableViewCell.h"
#import "Home2TableViewCell.h"
#import "Home5TableViewCell.h"
#import "BacklogMatterListModel.h"
#import "SignInViewController.h"
#import "GetDayAreaModel.h"
#import "SignBtnStatusModel.h"
#import "MessageCenterViewController.h"
#import "DutyListViewController.h"
#import "MyJobListViewController.h"
#import "SignInInfoModel.h"
#import "Home4TableViewCell.h"
#import "Home3TableViewCell.h"
#import "TaskDetailViewController.h"
#import "DutyDropListModel.h"
#import "SignInExplainView.h"
#import "SingInDetailViewController.h"
#import "SignInInfoView.h"
#import "WelcomeSignInView.h"
#import "GoOutRecordViewController.h"
#import "PersonGoOutDetailModel.h"
#import<BaiduMapAPI_Search/BMKGeocodeSearch.h>
#import<BaiduMapAPI_Location/BMKLocationService.h>
#import "UserInfoModel.h"

#define GetDayArea @"GetDayArea"//获取个人当天时间段划分及按钮状态
#define getSigninInfo @"getSigninInfo"//签到首界面
#define getDropList @"getDropList"
#define postBusinessRecordInfo @"postBusinessRecordInfo"//提交公出记录
#define getUserInfo @"getUserInfo"


@interface HomeViewController ()<UITableViewDelegate,UITableViewDataSource,BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate>
{
    SZCalendarPicker *_calendarPicker;
    UITableView *_tableView;//列表
    NSTimer *_timer;//定时器
    //GetDayAreaModel *_dayModel;//
    SignInInfoModel *_signInfoModel;
    NSInteger _photoPageCount;//当前图片的页数
    NSInteger _photoNum;//照片的总数量
    BMKLocationService *_locService;  //定位
    BMKGeoCodeSearch *_geocodesearch; //地理编码主类，用来查询、返回结果信息
    MyImageView *_headImageView;//个人中心头像
}
@property (nonatomic,assign) BOOL isSearch;//是否是历史数据
@property (nonatomic,strong) UserInfoModel *infoModel;
@property (nonatomic,strong) NSString *vacateBillId;//公出的id
@property (nonatomic,strong) NSMutableArray *goOutBeginArr;//记录公出开始时间的数组
@property (nonatomic,strong) NSMutableArray *goOutnEndArr;//记录公出结束时间的数组
@property (nonatomic,strong) SignBtnStatusModel *signButtonModel;
@property (nonatomic,strong) NSString *chooseDate;//选择的日期
@property (nonatomic,strong) DutyDropListModel *dutyDropListModel;//功能列表
@property (nonatomic,strong) UILabel *messageLabel;//最新消息label
@property (nonatomic,strong) UILabel *messageCountLabel;//
@property (nonatomic,strong) UILabel *endTimeLabel;//下班倒计时时间label
@property (nonatomic,strong) NSString *endTimeStr;//下班倒计时时间str
@property (nonatomic,assign) NSInteger endTime;//下班倒计时时间
@property (nonatomic,strong) UILabel *beginTimeLabel;//上班倒计时时间label
@property (nonatomic,strong) NSString *beginTimeStr;//上班倒计时时间str
@property (nonatomic,assign) NSInteger beginTime;//上班倒计时时间
@property (nonatomic,strong) UILabel *goOutBeginLabel;//公出开始倒计时时间label
@property (nonatomic,strong) NSString *goOutBeginStr;//公出开始倒计时时间str
@property (nonatomic,assign) NSInteger goOutBeginTime;//公出开始倒计时时间
@property (nonatomic,strong) UILabel *goOutEndLabel;//公出结束倒计时时间label
@property (nonatomic,strong) NSString *goOutEndStr;//公出结束倒计时时间str
@property (nonatomic,assign) NSInteger goOutEndTime;//公出结束倒计时时间

@property (nonatomic,strong) NSString *signTimeSep;//
@property (nonatomic,strong) SignBtnStatusModel *signStatusModel;//当前所处时间段的model
@property (nonatomic,strong) UIButton *gobackButton;//回到今日
@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(signOutSuccess:) name:@"signOutSuccess" object:nil];
    [self creatView];
    //[self requestBacklogMatterList];
    [self serverDateRequest];
    [self getDropListRequest];
    [self setRightBackNavigation];
    [self setLeftBackNavigation];
    [self setCenterButtonNavigation];
    [self userInfoRequest];

    self.view.backgroundColor=COLOR_BACKGROUND_GRAY;
    _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerFunc) userInfo:nil repeats:YES];
    
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self requestBacklogMatterListWithDateStr:nil];
    [self requestButtonStatusRequest];
}

#pragma mark -定时器刷新函数
- (void)timerFunc

{
    //[self requestButtonStatusRequest];
    //如果时差不等于0时 开始计算
    if (self.endTime>0) {
        int hour = (int)(self.endTime/3600);
        
        int minute = (int)(self.endTime - hour*3600)/60;
        
        int second =(int) self.endTime - hour*3600 - minute*60;
        if (hour>0) {
            self.endTimeLabel.text = [NSString stringWithFormat:@"倒计时 %02d:%02d:%02d", hour, minute,second];
        }else{
            self.endTimeLabel.text = [NSString stringWithFormat:@"倒计时 %02d:%02d", minute,second];
        }
        //当时间小于3分钟  显示红色字体
        if (minute<3&&hour==0) {
            self.endTimeLabel.textColor=[UIColor redColor];
        }else{
            self.endTimeLabel.textColor=[UIColor grayColor];
        }
        self.endTime--;
        self.endTimeLabel.hidden=NO;
    }else{
        self.endTimeLabel.hidden=YES;
    }
    
    //签到开始倒计时
    if (self.beginTime>0) {
        int hour = (int)(self.beginTime/3600);
        
        int minute = (int)(self.beginTime - hour*3600)/60;
        
        int second =(int) self.beginTime - hour*3600 - minute*60;
        if (hour>0) {
            self.beginTimeLabel.text = [NSString stringWithFormat:@"倒计时 %02d:%02d:%02d", hour, minute,second];
        }else{
            self.beginTimeLabel.text = [NSString stringWithFormat:@"倒计时 %02d:%02d", minute,second];
        }
        //当时间小于3分钟  显示红色字体
        if (minute<3&&hour==0) {
            self.beginTimeLabel.textColor=[UIColor redColor];
        }else{
            self.beginTimeLabel.textColor=[UIColor grayColor];
        }
        self.beginTime--;
        self.beginTimeLabel.hidden=NO;
    }else{
        self.beginTimeLabel.hidden=YES;
    }
    //公出开始倒计时
    if (self.goOutBeginTime>0) {
        int hour = (int)(self.goOutBeginTime/3600);
        
        int minute = (int)(self.goOutBeginTime - hour*3600)/60;
        
        int second =(int) self.goOutBeginTime - hour*3600 - minute*60;
        if (hour>0) {
            self.goOutBeginLabel.text = [NSString stringWithFormat:@"倒计时 %02d:%02d:%02d", hour, minute,second];
        }else{
            self.goOutBeginLabel.text = [NSString stringWithFormat:@"倒计时 %02d:%02d", minute,second];
        }
        //当时间小于3分钟  显示红色字体
        if (minute<3&&hour==0) {
            self.goOutBeginLabel.textColor=[UIColor redColor];
        }else{
            self.goOutBeginLabel.textColor=[UIColor grayColor];
        }
        self.goOutBeginTime--;
        self.goOutBeginLabel.hidden=NO;
    }else{
        self.goOutBeginLabel.hidden=YES;
    }
    //公出结束倒计时
    if (self.goOutEndTime>0) {
        int hour = (int)(self.goOutEndTime/3600);
        
        int minute = (int)(self.goOutEndTime - hour*3600)/60;
        
        int second =(int) self.goOutEndTime - hour*3600 - minute*60;
        if (hour>0) {
            self.goOutEndLabel.text = [NSString stringWithFormat:@"倒计时 %02d:%02d:%02d", hour, minute,second];
        }else{
            self.goOutEndLabel.text = [NSString stringWithFormat:@"倒计时 %02d:%02d", minute,second];
        }
        //当时间小于3分钟  显示红色字体
        if (minute<3&&hour==0) {
            self.goOutEndLabel.textColor=[UIColor redColor];
        }else{
            self.goOutEndLabel.textColor=[UIColor grayColor];
        }
        self.goOutEndTime--;
        self.goOutEndLabel.hidden=NO;
    }else{
        self.goOutEndLabel.hidden=YES;
    }
    
    
    static unsigned int num;
    num++;
    //每隔60秒刷新一次页面数据
    if (num%60==0&&_isSearch==NO) {
        [self requestBacklogMatterListWithDateStr:nil];
        [self requestButtonStatusRequest];
    }
    //每隔600秒开启一次定位
    if (num%600==0) {
        //如果当前时间是在公出中 启动定位
        if ([self isContainsNowTimeInGoOutTime:nil]) {
            [self startLocation];
        }

    }
    if (self.vacateBillId) {
        NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
        NSString *filePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:self.vacateBillId];
        //如果有文件夹则提交
        if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
            //如果当前时间是在公出结束后  提交数据
            if ([self isCanSubmitBusinessRecordInfo]) {
                [self postBusinessRecordInfoRequest];
            }
        }
    }
}
#pragma mark -签到通知
- (void)signOutSuccess:(NSNotification *)notification{
    NSDictionary *dict=[notification userInfo];
    [LZXHelper postMessageWithText:dict[@"userInfo"] View:self.view];
    [self requestButtonStatusRequest];
}

#pragma mark - 开始定位
-(void)startLocation
{
    if (!_locService) {
        _geocodesearch = [[BMKGeoCodeSearch alloc] init];
        
        _geocodesearch.delegate = self;
        //初始化BMKLocationService
        _locService = [[BMKLocationService alloc]init];
        _locService.delegate = self;
        _locService.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    }
    //启动LocationService
    [_locService startUserLocationService];
}

#pragma mark - 处理位置坐标更新
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    //地理反编码
    BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
    reverseGeocodeSearchOption.reverseGeoPoint = userLocation.location.coordinate;
    BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];
    
    if(flag){
        NSLog(@"反geo检索发送成功");
        //停止定位
        [_locService stopUserLocationService];
    }else{
        NSLog(@"反geo检索发送失败");
    }
}


#pragma mark -------------地理反编码的delegate---------------
-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
    //获取定位成功后的时间
    NSDateFormatter *formatter=[NSDateFormatter new];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    PersonGoOutDetailModel *model=[PersonGoOutDetailModel new];
    model.OBAddress=result.address;
    model.longitude=[NSString stringWithFormat:@"%f",result.location.longitude];
    model.latitude=[NSString stringWithFormat:@"%f",result.location.latitude];
    model.locationTime=[formatter stringFromDate:[NSDate date]];
    model.TOffId=self.vacateBillId;
    [self saveDownloadModelWithDownloadObject:model];
    //addressDetail:     层次化地址信息
    //address:    地址名称
    //businessCircle:  商圈名称
    // location:  地址坐标
    //  poiList:   地址周边POI信息，成员类型为BMKPoiInfo
}


#pragma mark -右边导航栏
- (void)setRightBackNavigation{
    //
    UIBarButtonItem *item=[[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"k_yingyong_time@2x"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(rightItemClick:)];
    [item setTintColor:[UIColor whiteColor]];
    self.navigationItem.rightBarButtonItem=item;
    //    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:13], NSFontAttributeName, [UIColor whiteColor], NSFontAttributeName, nil] forState:UIControlStateNormal];
}

#pragma mark -左边导航栏
- (void)setLeftBackNavigation{
    _headImageView=[[MyImageView alloc]initWithFrame:CGRectMake(0, 0,40, 40)];
    _headImageView.layer.masksToBounds=YES;
    _headImageView.layer.cornerRadius=_headImageView.width/2;
    [_headImageView addTarget:self action:@selector(backClick)];
    UIBarButtonItem *item=[[UIBarButtonItem alloc]initWithCustomView:_headImageView];
    self.navigationItem.leftBarButtonItem=item;
}
#pragma mark - 日历按钮
- (void)setCenterButtonNavigation{
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];//allocate titleView
    titleView.backgroundColor=[UIColor clearColor];
//    //Create UILable
//    UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(100, 0, 50, 20)];//allocate titleText
//    titleText.backgroundColor = [UIColor clearColor];
//    [titleText setText:@"Title"];
//    [titleView addSubview:titleText];
    
    //Create Round UIButton
    NSDateComponents *comp = [[NSCalendar currentCalendar] components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay|NSCalendarUnitWeekday) fromDate:[NSDate date]];
    
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(0, 0, 200, 20);
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitle:[NSString stringWithFormat:@"%li-%li-%li %@", (long)[comp year],(long)[comp month],(long)[comp day],[LZXHelper stringedWeekday:[comp weekday]]] forState:UIControlStateNormal];
    button.tag=105;
    [button addTarget:self action:@selector(dateClick:) forControlEvents:UIControlEventTouchUpInside];
    [titleView addSubview:button];
    //Set to titleView
    self.navigationItem.titleView = titleView;
}


#pragma mark - 日历点击
- (void)dateClick:(UIButton *)button{
    _isSearch=YES;
     _calendarPicker= [SZCalendarPicker showOnView:[[UIApplication sharedApplication].delegate window]];
    _calendarPicker.today = [NSDate date];
    if (_chooseDate) {
        NSDateFormatter *formatter=[NSDateFormatter new];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        NSDate *newDate=[formatter dateFromString:_chooseDate];
        _calendarPicker.date=newDate;
    }else{
        _calendarPicker.date = _calendarPicker.today;
    }
    _calendarPicker.frame = CGRectMake(0, 20, IPHONE_WIDTH, 400);
    __weak HomeViewController *mySelf=self;
    //选择日期的回调函数
    _calendarPicker.calendarBlock = ^(NSInteger day, NSInteger month, NSInteger year,NSInteger week){
        __block UIButton *button=(UIButton *)[mySelf.navigationItem.titleView viewWithTag:105];
        [button setTitle:[NSString stringWithFormat:@"%li-%li-%li %@", (long)year,(long)month,(long)day,[LZXHelper stringedWeekday:week]] forState:UIControlStateNormal];
        mySelf.chooseDate=[NSString stringWithFormat:@"%li-%li-%li",year,month,day];
        [mySelf requestBacklogMatterListWithDateStr:mySelf.chooseDate];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        
        [formatter setDateFormat:@"yyyy-MM-d"];
        NSString *dateStr = [formatter stringFromDate:[NSDate date]];
        //如果不是今天则显示回到今天按钮
        if (![dateStr isEqualToString:mySelf.chooseDate]) {
            mySelf.gobackButton.hidden=NO;
            UIButton *signIn=(UIButton *)[mySelf.view viewWithTag:251];
            UIButton *signOut=(UIButton *)[mySelf.view viewWithTag:250];
            signIn.hidden=YES;
            signOut.hidden=YES;
        }else{
            mySelf.gobackButton.hidden=YES;
            UIButton *signIn=(UIButton *)[mySelf.view viewWithTag:251];
            UIButton *signOut=(UIButton *)[mySelf.view viewWithTag:250];
            signIn.hidden=NO;
            signOut.hidden=NO;
        }
        mySelf.isSearch=NO;
        //NSLog(@"%i-%li-%li-%@", year,(long)month,(long)day,[LZXHelper stringedWeekday:week]);
    };
    
    _calendarPicker.viewHide=^(){
        mySelf.isSearch=NO;
    };
}
#pragma mark -返回上一页面
- (void)backClick{
    PersonCenterViewController *person=[PersonCenterViewController new];
    person.infoModel=self.infoModel;
    [self.navigationController pushViewController:person animated:YES];
}
#pragma mark -职责点击事件
- (void)dutyButtonClick{
    DutyListViewController *duty=[DutyListViewController new];
    [self.navigationController pushViewController:duty animated:YES];
}
////设置导航栏右边头像
//- (void)setRightBackNavigation{
//    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
//    //imageView setImageWithURL:<#(nonnull NSURL *)#> placeholderImage:<#(nullable UIImage *)#>
//    imageView.layer.masksToBounds=YES;
//    imageView.layer.cornerRadius=22;
//    UIBarButtonItem *item=[[UIBarButtonItem alloc]initWithCustomView:imageView];
//    self.navigationItem.rightBarButtonItem=item;
//}
#pragma mark - rightItemClick
- (void)rightItemClick:(UIBarButtonItem *)item{
    ApplicationListViewController *app=[ApplicationListViewController new];
    [self.navigationController pushViewController:app animated:YES];
}

#pragma mark -回到今天按钮
- (void)gobackButtonClick{
    UIButton *signIn=(UIButton *)[self.view viewWithTag:251];
    UIButton *signOut=(UIButton *)[self.view viewWithTag:250];
    signIn.hidden=NO;
    signOut.hidden=NO;
    //隐藏按钮并发请求
    self.gobackButton.hidden=YES;
    [self requestBacklogMatterListWithDateStr:nil];
    NSDateComponents *comp = [[NSCalendar currentCalendar] components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay|NSCalendarUnitWeekday) fromDate:[NSDate date]];
    //改变导航栏日期 回到今天
    UIButton *button=(UIButton *)[self.navigationItem.titleView viewWithTag:105];
    [button setTitle:[NSString stringWithFormat:@"%li-%li-%li %@", (long)[comp year],(long)[comp month],(long)[comp day],[LZXHelper stringedWeekday:[comp weekday]]] forState:UIControlStateNormal];

}

#pragma mark - creatTableView
- (void)creatView{
    //查看消息按钮
    UIButton *messageBtn=[MyControl creatButtonWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 40) target:self sel:@selector(openMessageCenter) tag:190 image:nil title:@""];
    messageBtn.backgroundColor=COLOR_SKYBLUE;
    [messageBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:messageBtn];
    //小喇叭
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 12, 16, 16)];
    imageView.image=[UIImage imageNamed:@"k_message@2x"];
    [messageBtn addSubview:imageView];
    
    self.messageLabel=[MyControl creatLabelWithFrame:CGRectMake(imageView.x+imageView.width+10, 0, IPHONE_WIDTH-48-(imageView.x+imageView.width+10)-140, 40) text:@"目前没有最新消息!"];
    self.messageLabel.textColor=[UIColor whiteColor];
    [messageBtn addSubview:self.messageLabel];
    
    self.messageCountLabel=[MyControl creatLabelWithFrame:CGRectMake(IPHONE_WIDTH-160, 0, 90, 40) text:@"0条未读"];
    self.messageCountLabel.textColor=[UIColor whiteColor];
    self.messageCountLabel.textAlignment=NSTextAlignmentRight;
    [messageBtn addSubview:self.messageCountLabel];
    //查看
    UILabel *clickLabel=[MyControl creatLabelWithFrame:CGRectMake(IPHONE_WIDTH-48, 0, 40, 40) text:@"查看"];
    clickLabel.textColor=[UIColor whiteColor];
    [messageBtn addSubview:clickLabel];
    
    //列表
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0,40, IPHONE_WIDTH, IPHONE_HEIGHT-40) style:UITableViewStylePlain];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.backgroundColor=[UIColor clearColor];
    _tableView.showsVerticalScrollIndicator=NO;
    _tableView.showsHorizontalScrollIndicator=NO;
    _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _tableView.bounces=NO;
    [self.view addSubview:_tableView];
    
    //下方空白的view
    UIView *footView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 80+64)];
    _tableView.tableFooterView=footView;
    
    //添加签到签退按钮
    NSArray *buttonTitle=@[@"签退",@"签到"];
    for (int i=0; i<buttonTitle.count; i++) {
        UIButton *signIn=[MyControl creatButtonWithFrame:CGRectMake(IPHONE_WIDTH-60-20*(i+1)-60*i, IPHONE_HEIGHT-64-80, 60, 60) target:self sel:@selector(signButtonClick:) tag:250+i image:nil title:buttonTitle[i]];
        [signIn setBackgroundColor:COLOR_MIDBLUE];
        signIn.layer.masksToBounds=YES;
        signIn.hidden=YES;
        signIn.layer.cornerRadius=signIn.width/2;
        [signIn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        signIn.titleLabel.font=FONT_17;
        [self.view addSubview:signIn];
    }
    //回到今天
    self.gobackButton=[UIButton buttonWithType:UIButtonTypeCustom];
    self.gobackButton.frame=CGRectMake(IPHONE_WIDTH-60-20, IPHONE_HEIGHT-80-64, 60, 60);
    [self.gobackButton setBackgroundColor:COLOR_MIDBLUE];
    [self.gobackButton addTarget:self action:@selector(gobackButtonClick) forControlEvents:UIControlEventTouchUpInside];
    self.gobackButton.layer.masksToBounds=YES;
    self.gobackButton.hidden=YES;
    self.gobackButton.titleLabel.font=FONT_13;
    [self.gobackButton setTitle:@"回到今天" forState:UIControlStateNormal];
    self.gobackButton.layer.cornerRadius=self.gobackButton.width/2;
    [self.gobackButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:self.gobackButton];
}

#pragma mark -异常说明
- (void)creatSignInExplainViewWithStr:(NSString *)str{
    NSArray *titleArr=@[@"原因说明",@"请假",@"公出",@"不说明"];
    SignInExplainView *explain=[[SignInExplainView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) listModel:_dutyDropListModel titleArr:titleArr titleStr:str];
    explain.homeController=self;
    [[[UIApplication sharedApplication].delegate window] addSubview:explain];
}

#pragma mark -照片查看
- (void)creatPhotoViewWithPhotoUrl:(NSString *)photoUrl address:(NSString *)address time:(NSString *)time{
    _photoPageCount=0;
    UIButton *photoView=[MyControl creatButtonWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) target:self sel:@selector(cancelPhotoClick:) tag:200 image:nil title:@""];
    photoView.backgroundColor=[UIColor clearColor];
    [[[UIApplication sharedApplication].delegate window] addSubview:photoView];
    
    //半透明的view
    UIView *alphaView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT)];
    alphaView.backgroundColor=[UIColor blackColor];
    alphaView.alpha=0.5;
    alphaView.userInteractionEnabled=NO;
    [photoView addSubview:alphaView];
    
    NSArray *infoArr=[photoUrl componentsSeparatedByString:@"|"];
    _photoNum=infoArr.count;
    //滚动视图
    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, (IPHONE_HEIGHT-(IPHONE_WIDTH-40-60))/2, IPHONE_WIDTH, IPHONE_WIDTH-40-60)];
    scrollView.contentSize=CGSizeMake(IPHONE_WIDTH*infoArr.count, 0);
    scrollView.tag=180;
    scrollView.bounces=NO;
    scrollView.userInteractionEnabled=NO;
    scrollView.pagingEnabled=YES;
    scrollView.scrollEnabled=NO;
    [photoView addSubview:scrollView];
    for (int i=0; i<infoArr.count; i++) {
        //照片
        UIImageView *photo=[[UIImageView alloc]initWithFrame:CGRectMake(20+scrollView.width*i, 0, IPHONE_WIDTH-40, scrollView.height)];
        [photo setImageWithURL:[NSURL URLWithString:infoArr[i]] placeholderImage:[UIImage imageNamed:@"ic_pic_bg@2x"]];
        [scrollView addSubview:photo];
    }
    //如果不止一张图片 则添加向左向右按钮
    if (infoArr.count>1) {
        UIButton *leftButton=[MyControl creatButtonWithFrame:CGRectMake(5, scrollView.y+(scrollView.height-40)/2, 50, 50) target:self sel:@selector(leftPhotoClick:) tag:220 image:nil title:@""];
        [leftButton setImage:[UIImage imageNamed:@"jiantou_left@2x"] forState:UIControlStateNormal];
        leftButton.layer.masksToBounds=YES;
        leftButton.layer.cornerRadius=leftButton.width/2;
        leftButton.backgroundColor=[UIColor whiteColor];
        leftButton.hidden=YES;
        leftButton.alpha=0.8;
        [photoView addSubview:leftButton];
        
        UIButton *rightButton=[MyControl creatButtonWithFrame:CGRectMake(IPHONE_WIDTH-5-50,scrollView.y+(scrollView.height-50)/2, 50, 50) target:self sel:@selector(rightPhotoClick:) tag:221 image:nil title:@""];
        rightButton.layer.masksToBounds=YES;
        [rightButton setImage:[UIImage imageNamed:@"jiantou_right@2x"] forState:UIControlStateNormal];
        rightButton.layer.cornerRadius=leftButton.width/2;
        rightButton.backgroundColor=[UIColor whiteColor];
        rightButton.alpha=0.8;
        [photoView addSubview:rightButton];
    }
    
    //图片信息背景
    UIView *titleView=[[UIView alloc]initWithFrame:CGRectMake(20, IPHONE_HEIGHT-(35+50), IPHONE_WIDTH-40, 50)];
    titleView.alpha=0.5;
    titleView.userInteractionEnabled=NO;
    titleView.backgroundColor=[UIColor blackColor];
    [photoView addSubview:titleView];
    
    //地点
    UILabel *addressLabel=[MyControl creatLabelWithFrame:CGRectMake(60, titleView.y+5, titleView.width-120, 20) text:[NSString stringWithFormat:@"地点:%@",address]];
    addressLabel.font=FONT_13;
    addressLabel.textColor=[UIColor whiteColor];
    //计算高度
    CGFloat addressHeight=[LZXHelper textHeightFromTextString:addressLabel.text width:addressLabel.width fontSize:13]+3;
    addressLabel.height=addressHeight;
    [photoView addSubview:addressLabel];
    //时间
    UILabel *timeLabel=[MyControl creatLabelWithFrame:CGRectMake(60, addressLabel.y+addressLabel.height, titleView.width-120, 20) text:[NSString stringWithFormat:@"时间:%@",time]];
    timeLabel.textColor=[UIColor whiteColor];
    timeLabel.font=FONT_13;
    [photoView addSubview:timeLabel];
    titleView.height=30+addressHeight;
}

#pragma mark -查看照片向左按钮
- (void)leftPhotoClick:(UIButton *)button{
    _photoPageCount--;
    UIButton *photoButton=(UIButton *)button.superview;
    UIScrollView *scrolleView=(UIScrollView *)[photoButton viewWithTag:180];
    //滚动照片
    scrolleView.contentOffset=CGPointMake(_photoPageCount*IPHONE_WIDTH, 0);
    UIButton *leftButton=(UIButton *)[photoButton viewWithTag:220];
    UIButton *rightButton=(UIButton *)[photoButton viewWithTag:221];
//    if (_photoPageCount==_photoNum) {
//        rightButton.hidden=YES;
//    }else{
        rightButton.hidden=NO;
//    }
    if (_photoPageCount==0) {

        leftButton.hidden=YES;
    }else{
        leftButton.hidden=NO;
    }
}

#pragma mark -查看照片向右按钮
- (void)rightPhotoClick:(UIButton *)button{
    _photoPageCount++;
    UIButton *photoButton=(UIButton *)button.superview;
    UIScrollView *scrolleView=(UIScrollView *)[photoButton viewWithTag:180];
    //滚动照片
    scrolleView.contentOffset=CGPointMake(_photoPageCount*IPHONE_WIDTH, 0);
    UIButton *rightButton=(UIButton *)[photoButton viewWithTag:221];
    UIButton *leftButton=(UIButton *)[photoButton viewWithTag:220];
//    if (_photoPageCount==0) {
//        leftButton.hidden=YES;
//    }else{
        leftButton.hidden=NO;
//    }
    if (_photoPageCount==_photoNum-1) {
        rightButton.hidden=YES;
    }else{
        rightButton.hidden=NO;
    }
}


#pragma mark - 消息查看

- (void)openMessageCenter{
    MessageCenterViewController *message=[MessageCenterViewController new];
    [self.navigationController pushViewController:message animated:YES];
}

#pragma mark -待我处理的工作

- (void)workButtonClick{
    MyJobListViewController *job=[MyJobListViewController new];
    job.navaTitle=@"待我处理工作";
    job.jobState=@"0";
    [self.navigationController pushViewController:job animated:YES];
}


#pragma mark -我发起的工作

- (void)myWorkButtonClick{
    MyJobListViewController *job=[MyJobListViewController new];
    job.navaTitle=@"我发起的工作";
    job.jobState=@"1";
    [self.navigationController pushViewController:job animated:YES];
}

#pragma mark -照片查看取消
- (void)cancelPhotoClick:(UIButton *)button{
    [button removeFromSuperview];
}

#pragma mark -签到按钮点击
- (void)signButtonClick:(UIButton *)button{
    NSArray *titleArr=@[@"现在说明",@"稍后说明",@"取消"];
    NSInteger nowCount = 0;
    //遍历数据  计算当前所处的时间段
    for (SignBtnStatusModel *signModel in _signStatusModel.dataArr) {
        if ([self compareOneTime:signModel.Begin withAnotherTime:signModel.End newTime:nil]){
            nowCount=[_signStatusModel.dataArr indexOfObject:signModel];
            break;
        }
    }
    __weak HomeViewController *mySelf=self;
    NSArray *typeArr=@[@"未签到",@"未签退",@"迟到",@"旷工",@"早退"];
    if (_signStatusModel.dataArr.count>0) {
        SignBtnStatusModel *signModel=_signStatusModel.dataArr[nowCount];
        
        if (button.tag==251) {
            //获取签到提示信息 并切割
            NSArray *infoArr=[signModel.Tips_QD componentsSeparatedByString:@"|"];
            if (infoArr.count>1) {
                //1为正常签到  0为异常
                if ([infoArr[0] isEqualToString:@"0"]) {
                    NSString *typeString=@"";
                    for (NSString *typeStr in typeArr) {
                        if ([infoArr[1] rangeOfString:typeStr].location!=NSNotFound) {
                            typeString=typeStr;
                            break;
                        }
                    }
                    NSArray *messageArr=[infoArr[1] componentsSeparatedByString:typeString];
                    NSString *messageStr=@"";
                    NSMutableAttributedString *str3=nil;
                    if (messageArr.count>1) {
                        messageStr=[NSString stringWithFormat:@"%@%@%@",messageArr[0],typeString,messageArr[1]];
                        //设置富文本
                        str3 = [[NSMutableAttributedString alloc] initWithString:messageStr]; //创建一个NSMutableAttributedString
                        [str3 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange([messageArr[0] length],  typeString.length)]; // 关键步骤，设置指定位置文字的颜色
                        [str3 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20.0f] range:NSMakeRange([messageArr[0] length],  typeString.length)]; //关键步骤，设置指定位置文字的字号大小
                    }else{
                        str3=[[NSMutableAttributedString alloc] initWithString: infoArr[1]];
                    }
                        //弹出提示框
                        SignInInfoView *explain=[[SignInInfoView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) titleArr:titleArr titleStr:str3];
                        //现在说明
                        explain.nowBlock=^(){
                            NSArray *titleArr=@[@"",@"请假",@"公出",@"不说明"];
                            SignInExplainView *explain=[[SignInExplainView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) listModel:_dutyDropListModel titleArr:titleArr titleStr:@"签到说明"];
                            explain.homeController=mySelf;
                            [[[UIApplication sharedApplication].delegate window] addSubview:explain];
                        };
                        //稍后说明
                        explain.laterBlock=^(){
                            SignInViewController *sign=[SignInViewController new];
                            sign.titleStr=button.titleLabel.text;
                            sign.signTimeSep=mySelf.signTimeSep;
                            sign.eventState=mySelf.signButtonModel.event_State_QD;
                            sign.isPressed=mySelf.signButtonModel.ButtonIn;
                            //sign.signClass=[_dayModel.signClass copy];
                            [mySelf.navigationController pushViewController:sign animated:YES];
                        };
                        [[[UIApplication sharedApplication].delegate window] addSubview:explain];
                    
                }else{
                    if (infoArr.count>2) {
                        //1为正常签到  0为异常
                        //弹出提示框
                        NSArray *titleArr=@[@"好的",@"取消"];
                        WelcomeSignInView *welcome=[[WelcomeSignInView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) titleArr:titleArr titleStr:infoArr[1] message:infoArr[2] ImageStr:@"k_ic_singin@2x"];
                        welcome.myBlock=^(){
                            SignInViewController *sign=[SignInViewController new];
                            sign.titleStr=button.titleLabel.text;
                            sign.signTimeSep=mySelf.signTimeSep;
                            sign.eventState=mySelf.signButtonModel.event_State_QD;
                            sign.isPressed=mySelf.signButtonModel.ButtonIn;
                            //sign.signClass=[_dayModel.signClass copy];
                            [mySelf.navigationController pushViewController:sign animated:YES];
                        };
                        [[[UIApplication sharedApplication].delegate window] addSubview:welcome];
                    }
                }
            }else{
                SignInViewController *sign=[SignInViewController new];
                sign.titleStr=button.titleLabel.text;
                sign.signTimeSep=mySelf.signTimeSep;
                sign.eventState=mySelf.signButtonModel.event_State_QD;
                sign.isPressed=mySelf.signButtonModel.ButtonIn;
                //sign.signClass=[_dayModel.signClass copy];
                [self.navigationController pushViewController:sign animated:YES];
            }
            //否则点的是签退按钮
        }else{
            //获取签到提示信息 并切割
            NSArray *infoArr=[signModel.Tips_QT componentsSeparatedByString:@"|"];
            if (infoArr.count>1) {
                //1为正常签到  0为异常
                if ([infoArr[0] isEqualToString:@"0"]) {
                    NSString *typeString=@"";
                    for (NSString *typeStr in typeArr) {
                        if ([infoArr[1] rangeOfString:typeStr].location!=NSNotFound) {
                            typeString=typeStr;
                            break;
                        }
                    }
                    NSArray *messageArr=[infoArr[1] componentsSeparatedByString:typeString];
                    NSString *messageStr=@"";
                    NSMutableAttributedString *str3=nil;
                    if (messageArr.count>1) {
                        messageStr=[NSString stringWithFormat:@"%@%@%@",messageArr[0],typeString,messageArr[1]];
                        //设置富文本
                        str3 = [[NSMutableAttributedString alloc] initWithString: messageStr]; //创建一个NSMutableAttributedString
                        [str3 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange([messageArr[0] length],  typeString.length)]; // 关键步骤，设置指定位置文字的颜色
                        [str3 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20.0f] range:NSMakeRange([messageArr[0] length],  typeString.length)]; //关键步骤，设置指定位置文字的字号大小
                    }else{
                        str3=[[NSMutableAttributedString alloc] initWithString: infoArr[1]];
                    }
                    //弹出提示框
                    SignInInfoView *explain=[[SignInInfoView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) titleArr:titleArr titleStr:str3];
                    //现在说明
                    explain.nowBlock=^(){
                        NSArray *titleArr=@[@"",@"请假",@"公出",@"不说明"];
                        SignInExplainView *explain=[[SignInExplainView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) listModel:_dutyDropListModel titleArr:titleArr titleStr:@"签退说明"];
                        explain.homeController=mySelf;
                        [[[UIApplication sharedApplication].delegate window] addSubview:explain];
                    };
                    //稍后说明
                    explain.laterBlock=^(){
                        SignInViewController *sign=[SignInViewController new];
                        sign.titleStr=button.titleLabel.text;
                        sign.signTimeSep=mySelf.signTimeSep;
                        sign.eventState=mySelf.signButtonModel.event_State_QT;
                        sign.isPressed=mySelf.signButtonModel.ButtonOut;
                        //sign.signClass=[_dayModel.signClass copy];
                        [mySelf.navigationController pushViewController:sign animated:YES];
                    };
                    [[[UIApplication sharedApplication].delegate window] addSubview:explain];
                }else{
                    if (infoArr.count>2) {
                        //弹出提示框
                        NSArray *titleArr=@[@"好的",@"取消"];
                        WelcomeSignInView *welcome=[[WelcomeSignInView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) titleArr:titleArr titleStr:infoArr[1] message:infoArr[2] ImageStr:@"explain_icon_out@2x"];
                        welcome.myBlock=^(){
                            SignInViewController *sign=[SignInViewController new];
                            sign.titleStr=button.titleLabel.text;
                            sign.signTimeSep=mySelf.signTimeSep;
                            sign.eventState=mySelf.signButtonModel.event_State_QT;
                            sign.isPressed=mySelf.signButtonModel.ButtonOut;
                            //sign.signClass=[_dayModel.signClass copy];
                            [mySelf.navigationController pushViewController:sign animated:YES];
                        };
                        [[[UIApplication sharedApplication].delegate window] addSubview:welcome];
                    }
                }
            }else{
                SignInViewController *sign=[SignInViewController new];
                sign.titleStr=button.titleLabel.text;
                sign.signTimeSep=mySelf.signTimeSep;
                sign.eventState=mySelf.signButtonModel.event_State_QT;
                sign.isPressed=mySelf.signButtonModel.ButtonOut;
                //sign.signClass=[_dayModel.signClass copy];
                [self.navigationController pushViewController:sign animated:YES];
            }
        }
    }
}

#pragma mark -cell点击时间
- (void)cellButtonClick:(UIButton *)button{
    SignInInfoModel *model=_signInfoModel.dataArr[button.tag-1000];
    if ([model.eventState isEqualToString:@"1"]) {
        TaskDetailViewController *detail=[TaskDetailViewController new];
        //detail.jobState=self.jobState;
        detail.businessCode=model.businessCode;
        detail.vacateBillId=model.vacateBillId;
        //detail.sex=model.empSex;
        detail.isOperate=@"0";
        //detail.dealState=model.dealState;
        //detail.isOwn=model.isOwn;
        //    if (timeArr.count>1) {
        //        detail.beginStr=timeArr[0];
        //        detail.endStr=timeArr[1];
        //    }
        [self.navigationController pushViewController:detail animated:YES];
    }
}

#pragma mark -照片查看
- (void)photoImageView:(MyImageView *)imageView{
    [self creatPhotoViewWithPhotoUrl:imageView.urlStr address:imageView.nameStr time:imageView.timeStr];
}

#pragma mark- tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _signInfoModel.dataArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SignInInfoModel *model=_signInfoModel.dataArr[indexPath.section];
    //签到
     __weak HomeViewController *mySelf=self;
    if ([model.eventState isEqualToString:@"0"]) {
        NSString *cellID=@"home1";
        Home1TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[Home1TableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.myBlock=^(SignInInfoModel *model){
                NSString  *exceptionStatus=@"";
                if (model.eventStatus!=nil&&model.eventStatus.length>0) {
                    //
                    NSArray *infoArr=[model.eventStatus componentsSeparatedByString:@"|"];
                    if (infoArr.count==2) {
                        //取出状态
                        exceptionStatus=infoArr[0];
                    }
                }
                if ([exceptionStatus isEqualToString:@"3"]||[exceptionStatus isEqualToString:@"2"]) {
                    TaskDetailViewController *detail=[TaskDetailViewController new];
                    //detail.jobState=self.jobState;
                    detail.businessCode=model.businessCode;
                    detail.vacateBillId=model.vacateBillId;
                    //detail.sex=model.empSex;
                    detail.isOperate=@"0";
                    [mySelf.navigationController pushViewController:detail animated:YES];
                }else if([exceptionStatus isEqualToString:@"1"]){
                    NSString *titleStr=model.result;
                    [mySelf creatSignInExplainViewWithStr:titleStr];
                }
            };
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            
            [formatter setDateFormat:@"MM"];
            NSString *timestamp = [formatter stringFromDate:[NSDate date]];
            //上班签到 1 下班签退 2 公出开始5  公出结束6
            if ([model.result isEqualToString:@"签退"]) {
                cell.detailBlock=^(){
                    SingInDetailViewController *detail=[SingInDetailViewController new];
                    detail.dutyListModel=mySelf.dutyDropListModel;
                    detail.typeStr=@"1";
                    detail.navaTitleStr=[NSString stringWithFormat:@"%@月份下班签退详情",timestamp];
                    [mySelf.navigationController pushViewController:detail animated:YES];
                };
            }else if ([model.result isEqualToString:@"签到"]){
                cell.detailBlock=^(){
                    SingInDetailViewController *detail=[SingInDetailViewController new];
                    detail.dutyListModel=mySelf.dutyDropListModel;
                    detail.typeStr=@"0";
                    detail.navaTitleStr=[NSString stringWithFormat:@"%@月份上班签到详情",timestamp];
                    [mySelf.navigationController pushViewController:detail animated:YES];
                };
            }
        }
        [cell setCellInfoWithModel:model];
        //0 拍照签到 5wifi签到
        if ([model.way isEqualToString:@"0"]) {
            //如果有照片
            if (model.photoList.length>0) {
                //保存照片的信息
                //去掉前面的|
                if ([[model.photoList substringToIndex:1]isEqualToString:@"|"]) {
                    model.photoList=[model.photoList substringFromIndex:1];
                }
                //去掉最后面的|
                if ([[model.photoList substringFromIndex:model.photoList.length-1]isEqualToString:@"|"]) {
                    model.photoList =[model.photoList substringToIndex:model.photoList.length-1];
                }
                //切割字符串
                NSArray *infoArr=[model.photoList componentsSeparatedByString:@"|"];
                cell.photoImageView.urlStr=model.photoList;
                cell.photoImageView.nameStr=model.signInPlace;
                cell.photoImageView.timeStr=model.eventTime;
                [cell.photoImageView setImageWithURL:[NSURL URLWithString:infoArr.count>0?infoArr[0]:@""]placeholderImage:[UIImage imageNamed:@"ic_pic_bg@2x"]];
                [cell.photoImageView addTarget:self action:@selector(photoImageView:)];
            }else{
                cell.photoImageView.image=[UIImage imageNamed:@"k_ic_1paizhao@2x"];
            }
        }else if([model.way isEqualToString:@"5"]){
            cell.photoImageView.image=[UIImage imageNamed:@"k_ic_1wifi@2x"];
        }else if([model.way isEqualToString:@"1"]){
            cell.photoImageView.image=[UIImage imageNamed:@"k_ic_1nfc@2x"];
        }
        return cell;
        //已办待办
    }else if([model.eventState isEqualToString:@"2"]){
        NSString *cellID=@"home2";
        Home2TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[Home2TableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID isNeedGoOut:(model.vacateBillId.length>0?YES:NO)];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            //添加点击事件
            [cell.workButton1 addTarget:self action:@selector(workButtonClick) forControlEvents:UIControlEventTouchUpInside];
            [cell.workButton2 addTarget:self action:@selector(myWorkButtonClick) forControlEvents:UIControlEventTouchUpInside];
            [cell.dutyButton addTarget:self action:@selector(dutyButtonClick) forControlEvents:UIControlEventTouchUpInside];
            cell.myBlock=^(){
                //进入公出说明
                GoOutRecordViewController *record=[GoOutRecordViewController new];
                record.vacateBillId=model.vacateBillId;
                if (model.businessCode.length>0) {
                    //先切割
                    NSArray *infoArr=[model.businessCode componentsSeparatedByString:@"|"];
                    if (infoArr.count>1) {
                        record.addressX=infoArr[1];
                        record.addressY=infoArr[0];
                    }
                }
                [mySelf.navigationController pushViewController:record animated:YES];
            };
        }
        //填充cell
        [cell setCellInfoWithModel:model];
        //当前时间如果包含在公出时间内  设置线条颜色
        if ([self isContainsNowTimeInGoOutTime:model.eventTime]) {
            cell.lineImageView.backgroundColor=[UIColor redColor];
            self.vacateBillId=model.vacateBillId;
        }else{
            cell.lineImageView.backgroundColor=[UIColor lightGrayColor];
        }
        //        i
        return cell;
        //已处理的业务
    }else if([model.eventState isEqualToString:@"1"]){
        NSString *cellID=@"home3";
        Home3TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[Home3TableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            [cell.backButton addTarget:self action:@selector(cellButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        }
        cell.backButton.tag=1000+indexPath.section;
        //填充cell
        [cell setCellInfoWithModel:model];
        //当前时间如果包含在公出时间内  设置线条颜色
        if ([self isContainsNowTimeInGoOutTime:model.eventTime]) {
            cell.lineImageView.backgroundColor=[UIColor redColor];
            self.vacateBillId=model.vacateBillId;
        }else{
            cell.lineImageView.backgroundColor=[UIColor lightGrayColor];
        }
        return cell;
        //未来事件
    }else if([model.eventState isEqualToString:@"3"]){
        //
        NSString *cellID=@"home4";
        Home4TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[Home4TableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            //去说明回调函数
            cell.myBlock=^(SignInInfoModel *model){
                NSString  *exceptionStatus=@"";
                if (model.eventStatus!=nil&&model.eventStatus.length>0) {
                    //
                    NSArray *infoArr=[model.eventStatus componentsSeparatedByString:@"|"];
                    if (infoArr.count==2) {
                        //取出状态
                        exceptionStatus=infoArr[0];
                    }
                }
                if ([exceptionStatus isEqualToString:@"3"]||[exceptionStatus isEqualToString:@"2"]) {
                    TaskDetailViewController *detail=[TaskDetailViewController new];
                    //detail.jobState=self.jobState;
                    detail.businessCode=model.businessCode;
                    detail.vacateBillId=model.vacateBillId;
                    //detail.sex=model.empSex;
                    detail.isOperate=@"0";
                    [mySelf.navigationController pushViewController:detail animated:YES];
                }else if([exceptionStatus isEqualToString:@"1"]){
                    NSString *titleStr=model.result;
                    [mySelf creatSignInExplainViewWithStr:titleStr];
                }
            };
        }
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        
        [formatter setDateFormat:@"MM"];
        NSString *timestamp = [formatter stringFromDate:[NSDate date]];
        //上班签到 1 下班签退 2 公出开始5  公出结束6
        if ([model.eventCode isEqualToString:@"2"]) {
            self.endTimeLabel=cell.endTimeLabel;
            cell.detailBlock=^(){
                SingInDetailViewController *detail=[SingInDetailViewController new];
                detail.dutyListModel=mySelf.dutyDropListModel;
                detail.typeStr=@"1";
                detail.navaTitleStr=[NSString stringWithFormat:@"%@月份下班签退详情",timestamp];
                [mySelf.navigationController pushViewController:detail animated:YES];
            };
        }else if ([model.eventCode isEqualToString:@"1"]){
            self.beginTimeLabel=cell.endTimeLabel;

            cell.detailBlock=^(){
                SingInDetailViewController *detail=[SingInDetailViewController new];
                detail.dutyListModel=mySelf.dutyDropListModel;
                detail.typeStr=@"0";
                detail.navaTitleStr=[NSString stringWithFormat:@"%@月份上班签到详情",timestamp];
                [mySelf.navigationController pushViewController:detail animated:YES];
            };
        }else if ([model.eventCode isEqualToString:@"5"]&&[self isContainsNowTimeInGoOutTime:model.eventTime]){
            self.goOutBeginLabel=cell.endTimeLabel;
        }else if ([model.eventCode isEqualToString:@"6"]&&[self isContainsNowTimeInGoOutTime:model.eventTime]){
            self.goOutEndLabel=cell.endTimeLabel;
        }
        //填充cell
        [cell setCellInfoWithModel:model];
        //当前时间如果包含在公出时间内  设置线条颜色
        if ([self isContainsNowTimeInGoOutTime:model.eventTime]) {
            self.vacateBillId=model.vacateBillId;
            cell.lineImageView.backgroundColor=[UIColor redColor];
            cell.endTimeLabel.hidden=NO;
        }else{
            cell.lineImageView.backgroundColor=[UIColor lightGrayColor];
            cell.endTimeLabel.hidden=YES;
        }
        

        //判断当前时间是否处在事件时间后
        NSDate *dateA = [self getDateWithTimeStr:model.eventTime];
        
        NSDate *dateNow=[NSDate date];
        NSComparisonResult resultA = [dateNow compare:dateA];
        //设置背景颜色
        if (resultA==NSOrderedDescending){
            cell.backButton.backgroundColor=[UIColor lightGrayColor];
        }else{
            cell.backButton.backgroundColor=[UIColor whiteColor];
        }
//        int hour = (int)(self.endTime/3600);
//
//        int minute = (int)(self.endTime - hour*3600)/60;
//        if ((int)(self.endTime - hour*3600)/60) {
//            cell.stateImageView.image=[UIImage imageNamed:@"k_dian_2@2x"];
//        }else{
//            
//        }
        return cell;
    }else{
        //公出记录
        NSString *cellID=@"home5";
        Home5TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[Home5TableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            
        }
        [cell setCellInfoWithModel:model];
        //当前时间如果包含在公出时间内  设置线条颜色
        if ([self isContainsNowTimeInGoOutTime:model.eventTime]) {
            cell.lineImageView.backgroundColor=[UIColor redColor];
            cell.stateImageView.image=[UIImage imageNamed:@"k_dian_2@2x"];
        }else{
            cell.lineImageView.backgroundColor=[UIColor lightGrayColor];
            cell.stateImageView.image=[UIImage imageNamed:@"k_dian_3@2x"];
        }
        //0 拍照签到 5wifi签到
        if ([model.way isEqualToString:@"0"]) {
            //如果有照片
            if (model.photoList.length>0) {
                //保存照片的信息
                //去掉前面的|
                if ([[model.photoList substringToIndex:1]isEqualToString:@"|"]) {
                    model.photoList=[model.photoList substringFromIndex:1];
                }
                //去掉最后面的|
                if ([[model.photoList substringFromIndex:model.photoList.length-1]isEqualToString:@"|"]) {
                    model.photoList =[model.photoList substringToIndex:model.photoList.length-1];
                }
                //切割字符串
                NSArray *infoArr=[model.photoList componentsSeparatedByString:@"|"];
                cell.photoImageView.urlStr=model.photoList;
                cell.photoImageView.nameStr=model.eventName;
                cell.photoImageView.timeStr=model.eventTime;
                [cell.photoImageView setImageWithURL:[NSURL URLWithString:infoArr.count>0?infoArr[0]:@""]placeholderImage:[UIImage imageNamed:@"ic_pic_bg@2x"]];
                [cell.photoImageView addTarget:self action:@selector(photoImageView:)];
            }else{
                cell.photoImageView.image=[UIImage imageNamed:@"k_ic_1paizhao@2x"];
            }
        }else if([model.way isEqualToString:@"5"]){
            cell.photoImageView.image=[UIImage imageNamed:@"k_ic_1wifi@2x"];
        }else if([model.way isEqualToString:@"1"]){
            cell.photoImageView.image=[UIImage imageNamed:@"k_ic_1nfc@2x"];
        }
        return cell;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   SignInInfoModel *model=_signInfoModel.dataArr[indexPath.section];
    //待办
    if ([model.eventState isEqualToString:@"2"]) {
        return 126+(model.vacateBillId.length>0?58:0);
    }else if([model.eventState isEqualToString:@"3"]){
        if (model.result.length>0) {
            return 66;
        }else{
            return 41;
        }
    }else{
        return 66;
    }
}



#pragma mark -根据返回数据设置签到签退按钮
- (void)setSignInButtonWithModel:(SignBtnStatusModel *)model{
    UIButton *signIn=(UIButton *)[self.view viewWithTag:251];
    UIButton *signOut=(UIButton *)[self.view viewWithTag:250];
    if (self.gobackButton.hidden==YES) {
        signIn.hidden=NO;
        signOut.hidden=NO;
    }else{
        signIn.hidden=YES;
        signOut.hidden=YES;
    }
    if ([model.ButtonIn isEqualToString:@"0"]) {
        signIn.backgroundColor=[UIColor lightGrayColor];
        //signIn.userInteractionEnabled=NO;
    }else{
        signIn.backgroundColor=COLOR_MIDBLUE;
        ///signIn.userInteractionEnabled=YES;
    }
    if ([model.ButtonOut isEqualToString:@"0"]) {
        signOut.backgroundColor=[UIColor lightGrayColor];
        //signOut.userInteractionEnabled=NO;
    }else{
        signOut.backgroundColor=COLOR_MIDBLUE;
        //signOut.userInteractionEnabled=YES;
    }
}



#pragma mark -判断时间大小
- (BOOL)compareOneTime:(NSString *)beginStr withAnotherTime:(NSString *)endStr newTime:(NSString *)newDate
{

    NSDate *dateA = [self getDateWithTimeStr:beginStr];
    NSDate *dateB = [self getDateWithTimeStr:endStr];

    NSDate *dateNow=nil;
    //如果没有则默认当前时间
    if (newDate) {
        dateNow=[self getDateWithTimeStr:newDate];
    }else{
        dateNow=[NSDate date];
    }
    NSComparisonResult resultA = [dateA compare:dateNow];
    NSComparisonResult resultB = [dateNow compare:dateB];
    //NSOrderedAscending 大于
    //NSOrderedDescending 小于
    if (((resultA==NSOrderedAscending)&&(resultB==NSOrderedAscending))||resultA==NSOrderedSame||resultB==NSOrderedSame) {
        return YES;
    }else{
        return NO;
    }
}

#pragma mark -根据时间字符串获取nsdate对象
- (NSDate *)getDateWithTimeStr:(NSString *)timeStr{
    NSDate *date=nil;
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
    date=[dateFormatter dateFromString:timeStr];
    //多类型选择
    if (date==nil) {
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
        date = [dateFormatter dateFromString:timeStr];
    }
    if (date==nil) {
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        date = [dateFormatter dateFromString:timeStr];
    }
    return date;
}


#pragma mark- 是否提交公出记录
- (BOOL)isCanSubmitBusinessRecordInfo{
    BOOL isCanSubmit=NO;
    //判断公出开始时间和结束时间数都存在时再执行
    if ((self.goOutBeginArr.count==self.goOutnEndArr.count)&&self.goOutnEndArr.count!=0) {
        for (NSInteger i=0; i<self.goOutnEndArr.count; i++) {
            NSString *beginStr=self.goOutBeginArr[i];
            NSString *endStr=self.goOutnEndArr[i];
            //判断当前时间是否处在公出结束后
            NSDate *dateA = [self getDateWithTimeStr:beginStr];
            NSDate *dateB = [self getDateWithTimeStr:endStr];
            
            NSDate *dateNow=[NSDate date];
            NSComparisonResult resultA = [dateA compare:dateNow];
            NSComparisonResult resultB = [dateNow compare:dateB];
            //判断公出是否结束
            if ((resultA==NSOrderedAscending)&&(resultB==NSOrderedDescending)){
                isCanSubmit=YES;
                break;
            }
        }
    }
    
    return isCanSubmit;
}

#pragma mark -判断当前时间是否处在公出时间段内
- (BOOL)isContainsNowTimeInGoOutTime:(NSString *)newTime{
    BOOL isContaions=NO;
    //判断公出开始时间和结束时间数都存在时再执行
    if ((self.goOutBeginArr.count==self.goOutnEndArr.count)&&self.goOutnEndArr.count!=0) {
        for (NSInteger i=0; i<self.goOutnEndArr.count; i++) {
            NSString *beginStr=self.goOutBeginArr[i];
            NSString *endStr=self.goOutnEndArr[i];
            //判断公出是否已结束
            NSDate *dateB = [self getDateWithTimeStr:endStr];
            
            NSDate *dateNow=[NSDate date];
            NSComparisonResult resultA = [dateB compare:dateNow];
            //判断当前时间是否处在公出时间段
            if ([self compareOneTime:beginStr withAnotherTime:endStr newTime:newTime]&&resultA==NSOrderedDescending){
                isContaions=YES;
                break;
            }
        }
    }
    
    return isContaions;
}

#pragma mark -时间获取成功
- (void)timeRequestSuccess{
    //签退倒计时
    if (self.serviceTime&&self.endTimeStr&&self.endTime==0) {
        //计算时差
        NSDate *date1 = [self getDateWithTimeStr:self.serviceTime];
        NSDate *date2 = [self getDateWithTimeStr:self.endTimeStr];
        //计算时差
        NSTimeInterval aTimer = [date2 timeIntervalSinceDate:date1];
        self.endTime=aTimer;
    }
    //签到倒计时
    if (self.serviceTime&&self.beginTimeStr&&self.beginTime==0) {
        //计算时差
        NSDate *date1 = [self getDateWithTimeStr:self.serviceTime];
        NSDate *date2 = [self getDateWithTimeStr:self.beginTimeStr];
        NSTimeInterval aTimer = [date2 timeIntervalSinceDate:date1];
        self.beginTime=aTimer;
    }
    //公出开始倒计时
    if (self.serviceTime&&self.goOutBeginStr&&self.goOutBeginTime==0) {
        //计算时差
        NSDate *date1 = [self getDateWithTimeStr:self.serviceTime];
        NSDate *date2 = [self getDateWithTimeStr:self.goOutBeginStr];
        
        NSTimeInterval aTimer = [date2 timeIntervalSinceDate:date1];
        self.goOutBeginTime=aTimer;
    }
    
    //公出结束倒计时
    if (self.serviceTime&&self.goOutEndStr&&self.goOutEndTime==0) {
        //计算时差
        NSDate *date1 = [self getDateWithTimeStr:self.serviceTime];
        NSDate *date2 = [self getDateWithTimeStr:self.goOutEndStr];
        
        NSTimeInterval aTimer = [date2 timeIntervalSinceDate:date1];
        self.goOutEndTime=aTimer;
    }
}

#pragma mark - 首页请求
- (void)requestBacklogMatterListWithDateStr:(NSString *)dateStr{
    NSString *date=@"";
    if (dateStr) {
        date=dateStr;
    }else{
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        
        [formatter setDateFormat:@"yyyy-MM-dd"];
        date = [formatter stringFromDate:[NSDate date]];
    }

    NSDictionary *dict=@{
                         @"strDate":date,
                         };
    //    NSMutableDictionary *dict2=[[NSMutableDictionary alloc]init];
    //    [dict2 setObject:dict forKey:@"content"];
    //    [dict2 setObject:@"" forKey:@"sessionId"];
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    //        //NSDictionary转换为Data
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    //Data转换为JSON
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId><content>%@</content>",[LZXHelper getSessionID],str];
    
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getSigninInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        [self removeRefreshView];
         _signInfoModel=[[SignInInfoModel alloc]initWithResponse:responseObject];
        if ([_signInfoModel.code isEqualToString:@"200"]) {
            //取出上班和下班时间
            if ((!self.endTimeStr)||(!self.beginTimeStr)) {
                //初始化数组
                if (!self.goOutBeginArr) {
                    self.goOutBeginArr=[NSMutableArray new];
                }else{
                    [self.goOutBeginArr removeAllObjects];
                }
                if (!self.goOutnEndArr) {
                    self.goOutnEndArr=[NSMutableArray new];
                }else{
                    [self.goOutnEndArr removeAllObjects];
                }

                for (SignInInfoModel *model in _signInfoModel.dataArr) {
                    //上班签到 1 下班签退 2 公出开始5  公出结束6
                    if ([model.eventState isEqualToString:@"3"]) {
                        if ([model.eventCode isEqualToString:@"6"]) {
                            self.goOutEndStr=model.eventTime;
                            //添加公出结束时间
                            [self.goOutnEndArr addObject:model.eventTime];
                        }else if([model.eventCode isEqualToString:@"5"]){
                            self.goOutBeginStr=model.eventTime;
                            //添加公出开始时间
                            [self.goOutBeginArr addObject:model.eventTime];
                        }else if([model.eventCode isEqualToString:@"1"]){
                            self.beginTimeStr=model.eventTime;
                        }else if ([model.eventCode isEqualToString:@"2"]){
                            self.endTimeStr=model.eventTime;
                        }
                    }
                }
                
                [self timeRequestSuccess];
            }
            
            [_tableView reloadData];
            
            //判断有没有未读消息
            //如果有
            if (_signInfoModel.backlogCount!=nil&&_signInfoModel.backlogCount.length>0&&![_signInfoModel.backlogCount isEqualToString:@"0"]) {
                _messageLabel.text=[NSString stringWithFormat:@"您收到%@发来的消息!",_signInfoModel.name];
                _messageCountLabel.text=[NSString stringWithFormat:@"%@条未读",_signInfoModel.backlogCount];
            }else{
                //如果没有
                _messageLabel.text=@"目前没有最新消息!";
                _messageCountLabel.text=@"0条未读";
            }
        }else if([_signInfoModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_signInfoModel.msg View:self.view];
        }
        
    } failure:^(NSError *error) {
        [self addRefreshViewWithFrame:self.view.frame msg:INTERNET_ERROR backView:self.view refreshMsg:nil];
    }];
}

#pragma mark - 签到签退按钮控制
- (void)requestButtonStatusRequest{
    
    //        //NSDictionary转换为Data
//    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
//    //Data转换为JSON
//    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId><content></content>",[LZXHelper getSessionID]];
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:GetDayArea soapBody:soap success:^(id responseObject) {
       // [LZXHelper hideLoadViewWithView:self.view];
        _signStatusModel=[[SignBtnStatusModel alloc]initWithResponse:responseObject];
        if ([_signStatusModel.code isEqualToString:@"200"]) {
            for (SignBtnStatusModel *signModel in _signStatusModel.dataArr) {
//                NSLog(@"开始时间:%@",signModel.Begin);
//                NSLog(@"结束时间:%@",signModel.End);
                if ([self compareOneTime:signModel.Begin withAnotherTime:signModel.End newTime:nil]) {
                    [self setSignInButtonWithModel:signModel];
                    self.signButtonModel=signModel;
                    NSDateFormatter *dateFomatter=[NSDateFormatter new];
                    [dateFomatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
                    NSDate *beginDate=[dateFomatter dateFromString:signModel.Begin];
                    NSDate *endDate=[dateFomatter dateFromString:signModel.End];
                    [dateFomatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                    NSString *beginStr=[dateFomatter stringFromDate:beginDate];
                    NSString *endStr=[dateFomatter stringFromDate:endDate];
                    self.signTimeSep=[NSString stringWithFormat:@"%@|%@",beginStr,endStr];
//                    NSLog(@"现在时间处于%@---%@之间",signModel.Begin,signModel.End);
                    break;
                }else{
//                    NSLog(@"现在时间不处于%@---%@之间",signModel.Begin,signModel.End);
                }
            }

        }else if([_signStatusModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_signStatusModel.msg View:self.view];
        }
        
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark -获取当前时间请求

- (void)serverDateRequest{
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content></content>",[LZXHelper getSessionID]];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getServiceTime soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {
            NSDictionary *dataDict=responseObject[@"retContent"];
            self.serviceTime=[dataDict[@"serviceTime"] copy];
            [self timeRequestSuccess];
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -获取请假类型请求

- (void)getDropListRequest{
    NSDictionary *dict=@{
                         @"dataSwith":@"1",
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    //__weak DutyListViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getDropList soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        _dutyDropListModel=[[DutyDropListModel alloc]initWithResponse:responseObject];
        if ([_dutyDropListModel.code isEqualToString:@"200"]) {

        }else if([_dutyDropListModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_dutyDropListModel.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -归档定位数据
- (void)saveDownloadModelWithDownloadObject:(PersonGoOutDetailModel *)addressModel{
    NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *filePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:addressModel.TOffId];
    //如果没有文件夹则创建
    if(![[NSFileManager defaultManager] fileExistsAtPath:filePath]){
        [self createDirectoryNamed:addressModel.TOffId];
    }
    NSString* filename = [filePath stringByAppendingPathComponent:addressModel.locationTime];
    if ([self fileExistsWithName:addressModel.locationTime inDirectory:addressModel.TOffId]) {
        [self removeAddressModelWithPath:filename];
    }
    //归档对象 归档对象的路径
    [NSKeyedArchiver archiveRootObject:addressModel toFile:filename];
}

#pragma mark- 解归档
- (PersonGoOutDetailModel *)addressModelWithFileName:(NSString *)fileName modelID:(NSString *)modelID{
    NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString* filename = [[[paths objectAtIndex:0] stringByAppendingPathComponent:modelID] stringByAppendingPathComponent:fileName];
    return  [NSKeyedUnarchiver unarchiveObjectWithFile:filename];
}

#pragma mark -删除文件
- (void)removeAddressModelWithPath:(NSString *)path{
    //
    NSFileManager *manager=[NSFileManager defaultManager];
    if ([manager isDeletableFileAtPath:path]) {
        NSError *error=nil;
        [manager removeItemAtPath:path error:&error];

    }
}

#pragma mark -查找文件

- (BOOL)fileExistsWithName:(NSString *)fileName
               inDirectory:(NSString *)directoryName {
    BOOL exists = NO;
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachesDirectory = [paths objectAtIndex:0];
    
    // if no directory was provided, we look by default in the base cached dir
    if ([[NSFileManager defaultManager] fileExistsAtPath:[[cachesDirectory stringByAppendingPathComponent:directoryName] stringByAppendingPathComponent:fileName]]) {
        exists = YES;
    }
    
    return exists;
}

#pragma mark- 创建以公出id为名的定位信息文件夹  用于存储定位
- (BOOL)createDirectoryNamed:(NSString *)directory {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachesDirectory = [paths objectAtIndex:0];
    NSString *targetDirectory = [cachesDirectory stringByAppendingPathComponent:directory];
    
    NSError *error;
    //
    
    return [[NSFileManager defaultManager] createDirectoryAtPath:targetDirectory
                                     withIntermediateDirectories:YES
                                                      attributes:nil
                                                           error:&error];
}

#pragma mark -提交公出记录
- (void)postBusinessRecordInfoRequest{
    
    //添加照片信息
    NSMutableArray *imageInfoArr=[NSMutableArray new];
    //公出地址坐标
    NSMutableArray *requestArr=[NSMutableArray new];
    //modelListPath便是包含有该文件夹下所有文件的文件名及文件夹名的数组
    NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString* filePath= [[paths objectAtIndex:0] stringByAppendingPathComponent:self.vacateBillId];
    
    NSArray * modelListPath = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil];
    if (modelListPath.count==0) {
        return;
    }
    for (NSString *fileName in modelListPath) {
        //根据路径反归档数据
        PersonGoOutDetailModel *model=[NSKeyedUnarchiver unarchiveObjectWithFile:[filePath stringByAppendingPathComponent:fileName]];
        //参数
        NSDictionary *dict=@{
                             @"latitude":model.latitude?model.latitude:@"",
                             @"longitude":model.longitude?model.longitude:@"",
                             @"altitude":@"33",
                             @"address":model.OBAddress?model.OBAddress:@"0",
                             @"locationTime":model.locationTime?model.locationTime:@"",
                             };
        [requestArr addObject:dict];
    }
    
    NSDictionary *newDict=@{
                            @"id":self.vacateBillId?self.vacateBillId:@"",
                            @"locationList":requestArr,
                            @"picList":imageInfoArr,
                            };
    
    //    [picList setObject:imageArr forKey:@"picList"];
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:newDict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:postBusinessRecordInfo soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        //解析数据并保存用户数据
        //NSLog(@"%@",responseObject[@"msg"]);
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {
            [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
            [self removeAddressModelWithPath:filePath];
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
        
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
    
}


#pragma mark -用户信息请求
- (void)userInfoRequest{
    
    //    //请求
    NSDictionary *dict=@{
                         //                         @"password":_passWordTextField.text,
                         //                         @"username":_userTextField.text,
                         @"sessionId":[LZXHelper getSessionID],
                         //                        @"reqStr":@"weaqtfaw"
                         };
    //    //    NSMutableDictionary *dict2=[[NSMutableDictionary alloc]init];
    //    //    [dict2 setObject:dict forKey:@"content"];
    //    //    [dict2 setObject:@"" forKey:@"sessionId"];
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    //
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getUserInfo soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        _infoModel=[[UserInfoModel alloc]initWithResponse:responseObject];
        
        if ([_infoModel.code isEqualToString:@"200"]) {
            [_headImageView setImageWithURL:[NSURL URLWithString:_infoModel.img] placeholderImage:[UIImage imageNamed:@"k_portrait@2x"]];
        }else if([_infoModel.code isEqualToString:@"220"]){
            //[LZXHelper postMessageWithText:_infoModel.msg View:self.view];
        }
    } failure:^(NSError *error) {

    }];
    
}

#pragma mark -加载失败重新加载
- (void)refreshButtonClick{
    [self requestBacklogMatterListWithDateStr:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
